<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>{log_name} : {log_account_no}</title>
<link rel="shortcut icon" href="{dir_image}favicon.ico">
<link rel="stylesheet" type="text/css" href="{dir_css}Global.css" />
<link rel="stylesheet" type="text/css" href="{dir_css}Popup.css" />
<link rel="stylesheet" type="text/css" href="{dir_css}Registrar.css" />

<script type="text/javascript" src="{dir_js}jquery.min.js"></script>
<script type="text/javascript" src="{dir_js}Global.js"></script>
</head>

<body>
<!-- POPUP -->{page_popup}<!-- POPUP END -->
<!-- TOP HEADER -->{page_header}<!-- TOP HEADER END -->
	<div class="main-content">
		<input type="hidden" id="record_saved" value="{record_saved}"/>
		<table width="0" border="0" cellspacing="0" cellpadding="0">
			<tr valign="top" align="left">
				<td width="220">
					{dean_sub_menu}
				</td>
				<td width="755">
					<div class="page-sub-content">
						<div class="float-right-back"><a href="?page=Students"><img src="{dir_image}icon/back.png" border="0"/></a></div>	
						<div class="ann-top-label">Students Record</div>
						<table width="0" border="0" cellspacing="0" cellpadding="0">
							<tr>
								<td class="reg-student-enroll-td" width="110"><strong>Student #</strong></td>
								<td class="reg-student-enroll-td">:</td>
								<td class="reg-student-enroll-td">{stud_no}</td>
							</tr>
							<tr>
								<td class="reg-student-enroll-td"><strong>Name</strong></td>
								<td class="reg-student-enroll-td">:</td>
								<td class="reg-student-enroll-td">{last_name} {first_name} {middle_name}</td>
							</tr>
							<tr>
								<td class="reg-student-enroll-td"><strong>Department</strong></td>
								<td class="reg-student-enroll-td">:</td>
								<td class="reg-student-enroll-td">{dept_desc}</td>
							</tr>
							<tr>
								<td class="reg-student-enroll-td"><strong>Course</strong></td>
								<td class="reg-student-enroll-td">:</td>
								<td class="reg-student-enroll-td">{course_desc}</td>
							</tr>
							<tr>
								<td colspan="2"></td>
								<td><div class="enrollment-more-details"  onclick="popupRequest('show', 'StudentProfile', 'Student Profile', '390', '500', '{stud_id}');">More Details</div></td>
							</tr>
						</table>
						
						
						<div class="div-reg-transfery">
							<ul class="ul-reg-transfery">
								<li class="li-reg-transfery">Update Enrolled Subjects</li>
							</ul>
						</div>
						<div class="div-reg-pointer" id="click_type_reg_transfer">{sem_desc} ({sem_code}) <span class="font-blue">[{total_sem_units} <em>Units</em>]</span> </div>
						<form method="post" enctype="multipart/form-data" action="" onsubmit="return validateForm()" >
						
							<input type="hidden" id="sem_taken_active" value="{sem_taken_active}"/>
							<input type="hidden" id="sem_desc" value="{sem_desc}"/>
							<input type="hidden" id="stud_id" value="{stud_id}"/>
							<input type="hidden" id="year_id" value="{year_id}"/>
							<input type="hidden" id="course_id" value="{course_id}"/>
							<input type="hidden" id="redirect" value="{redirect}"/>
							<input type="hidden" id="total_sem_units" value="{total_sem_units}"/>
							
							<input type="hidden" id="active_subj" value="{active_subj}"/>
							<input type="hidden" id="active_subj2" value="{active_subj2}"/>
							
							<div id="enrollment_popup"></div>
							
							<div class="ajax-enrollment-value" id="enrollment_value_stud_subj"></div>
							<div id="enrollment_add_stud_subj"></div>
							
							<div class="ajax-enrollment-value" id="value_stud_subj"></div>
							
						</form>
					</div>
				</td>
			</tr>
		</table>
		
	</div>
<!-- FOOTER -->{page_footer}<!-- FOOTER -->
<script type="text/javascript">

	$(document).ready(function() {
		studCurrentEnrolled();
	});
	
	function studCurrentEnrolled() {
		
		var stud_val   		   	= $('#stud_id').val();
		var course_val   	   = $('#course_id').val();
		var sem_taken_active   = $('#sem_taken_active').val();
		var total_sem_units	   = $('#total_sem_units').val();
				
		var enrollment_value_stud_subj = $('#enrollment_value_stud_subj');
		enrollment_value_stud_subj.html('');
		var subj_transfery_first_key = '';
		var total_units = 0;
		
		$.post('request.php', {AJAXPost:'UpdateStudentEnrolled', stud_id:stud_val, course_id:course_val, sem_linker_id:sem_taken_active}, function(res) {
			if (res == 0) {
				enrollment_popup.append('<div class="enrollment-label">' + sem_desc + '</div><div class="ajax-enrollment-value">No Record Found.</div>');
			}
			else {
				var subj_active_list = $('#active_subj2').val();
				$.each(res, function(first_key, first_value) {
					getStudentSemesterDesc(first_key, 'sem_stud_grade_enroll_list22');
					subj_transfery_first_key += first_key + ',';
					enrollment_value_stud_subj.append('<div class="enrollment-label" id="sem_stud_grade_enroll_list22' + first_key + '"></div>');
					enrollment_value_stud_subj.append('<table width="0" border="0" cellspacing="0" cellpadding="0">');
					
					$.each(first_value, function(second_key, second_value) {
						if ( second_value['grade'] != '' ) {
							enrollment_value_stud_subj.append('<tr><td width="15" height="18"><img id="but_trans_subj_id' + second_value['subj_idPK'] + '" src="./application/images/icon/checkbox_remove.png" border="0" class="but_trans_subj_id cursor-pointer"/></td><td width="500"><span class="transfery_desc_code cursor-pointer">' + second_value['subj_desc'] + ' (' + second_value['subj_code'] +')</span></td><td width="100">' + Math.abs(second_value['total_units']) + ' Units</td></tr>');
						}
						else {
							enrollment_value_stud_subj.append('<tr class="hover-light">'+
																	'<td width="40" height="18">'+
																		'<input type="hidden" class="hidden_trans_subj_id" id="enrolled' + second_value['subj_idPK'] + '" value="1"/>'+
																		'<div class="icon-button">'+
																			'<img id="but_trans_subj_id' + second_value['subj_idPK'] + '" src="./application/images/icon/recyclebin.png" border="0" class="but_trans_subj_id cursor-pointer" onclick="popupDelete(\'' + second_value['subj_idPK'] + '\', \'190\')" />'+
																			'<div class="delete-button-near-img" id="delete_button_' + second_value['subj_idPK'] + '">'+
																				'<div class="delete-label">Delete <strong>' + second_value['subj_code'] + '</strong>?</div>'+
																				'<div class="delete-yes-no" onclick="deleteSubject(\'' + second_value['stud_subj_linker_idPK'] + '\');">Yes</div>'+
																				'<div class="delete-yes-no" onclick="popupDeleteHide(\'' + second_value['subj_idPK'] + '\');">No</div>'+
																			'</div>'+
																			'&nbsp;<img src="./application/images/icon/reports.png" border="0" class="but_trans_subj_id cursor-pointer" onclick="viewSchedule(\'' + second_value['subj_idPK'] + '\')"/>'+
																			'<div class="schedule-button-near-img schedule_view" id="schedule_button_' + second_value['subj_idPK'] + '">'+
																				'<div class="schedule-close" onclick="scheduleClose(\'' + second_value['subj_idPK'] + '\')"><img src="{dir_image}icon/close.png" border="0" /></div>'+
																				'<div id="schedule_view'+ second_value['subj_idPK'] +'"></div>'+
																			'</div>'+
																		'</div>'+
																	'</td>'+
																	'<td width="500">'+
																		'<span class="transfery_desc_code cursor-pointer">' + second_value['subj_desc'] + ' (' + second_value['subj_code'] +')</span>'+
																	'</td>'+
																	'<td width="60">' + Math.abs(second_value['total_units']) + ' Units</td>'+
																'</tr>');
						
						}
						subj_active_list += second_value['subj_idPK'] + '-';
						total_units += parseInt(Math.abs(second_value['total_units']));								
					});
					$('#active_subj').val(subj_active_list);
					enrollment_value_stud_subj.append('</table>');
				});
				
				if ( total_sem_units > total_units ) {
					$('#enrollment_add_stud_subj').html('<div class="regular-add-subj" onclick="enrollSubjectEnroll();"><table width="0" border="0" cellspacing="0" cellpadding="0"><tr valign="top"><td width="18" height="14"><input type="hidden" id="next_sem_img" value="0"/><img src="./application/images/icon/add.png" border="0" /></td><td class="font-white"><span id="subj_add_label">ADD</span> SUBJECT</td></tr></table></div><div id="fourth_year_sem"><div id="sem_stud_grade_enroll_list_next"></div></div>');
				}
			}
		},'json');
		
	}
	
	function scheduleClose(strID) {
		$('#schedule_button_'+strID).hide(function(){});
	}
	
	function popupSchedule(strID) {
		$('#schedule_button_'+strID).show(function(){});
	}
	
	function viewSchedule(strID) {
		$('.schedule_view').hide();
		$.post('request.php', {AJAXPost:'ScheduleSubject', subj_id:strID}, function(res) {
			$('#schedule_view'+strID).html('').append('<table width="0" border="0" cellspacing="0" cellpadding="0">');
			$.each( res, function( key, value ) {
				$('#schedule_view'+strID).append('<tr>'+
													'<td width="75" height="20" class="border-right-schedule">' + value['section_desc'] + '</td>'+
													'<td width="130" class="border-right-schedule">&nbsp;&nbsp;' + value['room_desc'] + '</td>'+
													'<td width="100" class="border-right-schedule">&nbsp;&nbsp;' + value['sched_day'] + '</td>'+
													'<td width="50">&nbsp;&nbsp;' + value['sched_from'] + '</td>'+
													'<td width="6">-</td>'+
													'<td width="50">&nbsp;&nbsp;' + value['sched_to'] + '</td>'+
												'</tr>');
				
			});
			$('#schedule_view'+strID).append('</table>');
			$('#schedule_button_'+strID).show();
		}, 'json');
	}
	
	function deleteSubject(strStudSubjLinkerID) {
		$.post('request.php', {AJAXPost:'DeleteSubjEnrolled', stud_subj_linker_id:strStudSubjLinkerID}, function(res) {
			if ( res == 1 ) studCurrentEnrolled();
			else linkNewPage('Students');
		}, 'json');
	}
	
	function addSubject(strStudID, strSubjID, strCourseID, strSemID, strYearID, strSemActive) {
		$.post('request.php', {AJAXPost:'AddSubjEnrolled', stud_id:strStudID, subj_id:strSubjID, course_id:strCourseID, sem_id:strSemID, year_id:strYearID, subj_taken:strSemActive}, function() {
			window.location.href = window.location.href;
		});
	}
	
	function getStudentSemesterDesc(strSem, strDdivID) {
		$.post('request.php', {AJAXPost:'Semester', sem_id:strSem}, function(res) {
			$('#'+strDdivID+strSem).text(res.sem_desc)
		}, 'json');
	}
	
	function enrollSubjectEnroll() {
		$('#list_subj_taken').val('');
		
		var ast   			= $('#active_subj_taken').val();
		var value_stud_subj	= $('#value_stud_subj');
		var stud_id   		= $('#stud_id').val();
		var course_id   	= $('#course_id').val();
		var course_desc   	= $('#course_desc').val();
		value_stud_subj.html('').append('<div class="stud-grade-subj-list"><div id="stud_grade_subj_enroll_list"></div><div id="enoll_transfery_sem_sub' + ast + '"></div></div>');
		//gradeSubjEnrollListing(stud_id, course_id);
		selectGradeTransfery($('#sem_desc').val(), ast)
	}
	
	function gradeSubjEnrollListing(strStudID, strCourseID) {
		var stud_grade_subj_enroll_list = $('#stud_grade_subj_enroll_list');
		stud_grade_subj_enroll_list.html('');
		//$.post('request.php', {AJAXPost:'preRequisiteEnrolled', strCourseID:strCourseID, strStudID:strStudID}, function(res) {
		$.post('request.php', {AJAXPost:'preRequisite', strCourseID:strCourseID}, function(res) {
			$.each( res, function( key, value ) {
				stud_grade_subj_enroll_list.append('<div class="enrollment-label cursor-pointer" id="enroll_trans_select_sem' + value['sem_linker_idPK'] + '" onclick="selectGradeTransfery(\'' + value['sem_desc'] + '\', \'' + value['sem_linker_idPK'] + '\');">'+
														'<img src="{dir_image}icon/check.png" border="0"/> ' + value['sem_desc'] + '</div>' +
													'</div><div id="enoll_transfery_sem_sub' + value['sem_linker_idPK'] + '"></div>');
			});
			
		}, 'json');
	}
	
	function selectGradeTransfery(strDesc, strSemLinker) {
		$('#active_subj_taken').val(strSemLinker);
		var strStudID = $('#stud_id').val();
		var strCourseID = $('#course_id').val();
		$.post('request.php', {AJAXPost:'gradeTotalUnitsPerSemester', sem_linker_id:strSemLinker}, function(res) {
			gradeSubjEnrollListingSubjects(strStudID, strCourseID, strSemLinker);
		}, 'json');
	}
	
	function gradeSubjEnrollListingSubjects(strStudID, strCourseID, strSemLinker) {
		var stud_grade_subj_enroll_list = $('#stud_grade_subj_enroll_list');
		stud_grade_subj_enroll_list.html('');
		var subj_transfery_first_key = '';
		$.post('request.php', {AJAXPost:'GradeSubjEnrollSemester', stud_id:strStudID, course_id:strCourseID, sem_linker_id:strSemLinker}, function(res) {
			
			$.each(res, function(first_key, first_value) {
				
				getStudentSemesterDesc(first_key, 'sem_stud_grade_enroll_list');
				subj_transfery_first_key += first_key + ',';
				stud_grade_subj_enroll_list.append('<div class="enrollment-label" id="sem_stud_grade_enroll_list' + first_key + '"></div>');
				stud_grade_subj_enroll_list.append('<table width="0" border="0" cellspacing="0" cellpadding="0">');
				$.each(first_value, function(second_key, second_value) {
					
					stud_grade_subj_enroll_list.append('<tr class="hover-light">'+
															'<td width="15" height="16">'+
																'<div id="button_enroll_get_data' + second_value['subj_idPK'] + '">'+
																	'<img src="{dir_image}icon/checkbox_uncheck.png" border="0" class="but_trans_subj_id cursor-pointer" onclick="addSubject(\'' + strStudID + '\', \'' + second_value['subj_idPK'] + '\', \'' + strCourseID + '\', \'' + first_key + '\', \'' + $('#year_id').val() + '\', \'' + $('#sem_taken_active').val() + '\');" />'+
																'<div>'+
															'</td>'+
															'<td width="500">'+
																'<span class="transfery_desc_code cursor-pointer" id="transfery_desc_code' + second_value['subj_idPK'] + '" onclick="addSubject(\'' + strStudID + ', \'' + second_value['subj_idPK'] + '\', \'' + strCourseID + '\', \'' + first_key + '\', \'' + $('#year_id').val() + '\', \'' + $('#sem_taken_active').val() + '\');">' + second_value['subj_desc'] + ' (' + second_value['subj_code'] +')</span>'+
															'</td>'+
															'<td width="100">' + Math.abs(second_value['total_units']) + ' Units</td></tr>');
					
				});
				stud_grade_subj_enroll_list.append('</table>');
			});
			
			getRequisiteData();
			
		}, 'json');
	}
	
		function getRequisiteData() {
			$.post('request.php', {AJAXPost:'requisiteSubjCourse', course_id:$('#course_id').val()}, function(res) {
				strArrayActiveSubj = $('#active_subj2').val().split('-');
				$.each(res, function(first_key, first_value) {
					$.each(first_value, function(second_key, second_value) {
						strResultInArray = $.inArray(second_value['pre_req'], strArrayActiveSubj);
						if(strResultInArray > 0) {
							$('#button_enroll_get_data'+second_value['subj_idFK']).html('<img src="{dir_image}icon/checkbox_remove.png" border="0" />');
							$('#transfery_desc_code'+second_value['subj_idFK']).attr('onclick', false);
						}
					});
				});
			}, 'json');
		}
			
</script>
</body>
</html>
